<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;

class SearchController extends BaseController {
    public function index(){
        
        $Article =M('Article');
        $order='createtime desc';
        //获取搜索文章
        $keywords =trim(I('search'));
        if ($keywords!=""){      
            $map_s['title'] = array('like',"%$keywords%");
        }else {
            $map_s['state']=1;
        }
        $article =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map_s)->order($order)->select();
        
        //颜色高亮
        foreach($article as $key=> $value)
        {
            $article[$key]['title'] =str_replace($keywords,"<em style='color:#f36903;'>$keywords</em>",$value['title']);
        }
       
        //获取推荐文章
        $map_hot['index_hot']=1;
        $map_hot['status']=1;
        $art_recom =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map_hot)->order($order)->limit(0,6)->select();
        
        $Ad =M('Picture');
        //获取广告图片
        $map_ad['state']=1;
        $map_ad['classify']=2;
        $ad =$Ad->where($map_ad)->limit(0,2)->select();
        $ad1=$ad[0];
        $ad2=$ad[1];
        
        $this->assign('article',$article);
        $this->assign('article_recom',$art_recom);
        $this->assign('ad1',$ad1);
        $this->assign('ad2',$ad2);
        $this->display('index');

    }
 
   
   
   
}